@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <div class="col-sm-11">
                            <h5>资质添加</h5>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="Form" action="/foradmin/aptitude/add" method="post">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">资质名称：</label>
                                <div class="col-sm-4">
                                    <input id="aptitude_name" name="aptitude_name" class="form-control" type="text" placeholder="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">级别：</label>
                                <div class="col-sm-2">
                                    <input name="aptitude_level[]" class="form-control" type="text" placeholder="">
                                </div>
                            </div>
                            <div class="aptitud_level_list">
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"></label>
                                <div class="col-sm-9">
                                    <p class=" control-label"><div class="btn btn-xs btn-primary aptitud_level_add">+</div></p>
                                </div>
                                <label class="col-sm-3 control-label"></label>
                                <div class="col-sm-9">
                                    <p class="control-label" style="text-align: left;">如资质无级别区分，此栏位不填</p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">状态：</label>
                                <div class="col-sm-2">
                                    <select class="form-control">
                                        <option>未审核</option>
                                        <option>已审核</option>
                                        <option>未通过</option>
                                    </select>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <a href="/foradmin/aptitude" class="btn btn-default pull-left">返回</a>
                                <button type="submit" class="btn btn-primary" id="btn_submit">
                                    确定
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <script src="{{asset('js/plugins/layer/layer.min.js')}}"></script>
    <script>
        $(document).ready(function () {
            $('.aptitud_level_add').click(function(event) {
                var a = '<div class="form-group">'
                                +'<label class="col-sm-3 control-label"></label>'
                                +'<div class="col-sm-2">'
                                    +'<input name="aptitud_level[]" class="form-control" type="text" placeholder="">'
                                +'</div>'
                                +'<div class="col-sm-2">'
                                    +'<p class=" control-label"><div class="btn btn-xs btn-danger aptitud_level_del">×</div></p>'
                                +'</div>'
                            +'</div>';
                $('.aptitud_level_list').append(a);
            });
            $(document).on('click','.aptitud_level_del',function(event) {
                $(this).parent().parent().remove();
            });
            var icon = "<i class='fa fa-times-circle'></i> ";
            $("#Form").validate({
                rules: {
                    aptitude_name: {
                        required:true
                    }
                },
                messages: {
                    aptitude_name: {
                        required:icon + "请输入资质名称"
                    }
                },
                submitHandler:function(form){

                    var data = $("#Form").serialize();
                    $.ajax({
                        url : '/foradmin/aptitude/add',
                        type : 'POST',
                        dataType : "json",
                        data : data,
                        success : function(data) {
                            if (0 == data.code) {
                                layer.alert('添加成功', {
                                    icon: 1
                                }, function () {
                                    location.href = "/foradmin/aptitude";
                                });
                            } else {
                                layer.alert(data.message, {
                                    icon: 2
                                });
                            }
                        },
                    });


                }
            });

        });
    </script>
@endsection
